<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>libfuse: example/passthrough.c File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">libfuse
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',false,false,'search.php','Search');
});
</script>
<div id="main-nav"></div>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_cfafba98a580ce4b62f8a6fa96d7cbb0.html">example</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">passthrough.c File Reference</div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><code>#include &lt;<a class="el" href="fuse_8h_source.html">fuse.h</a>&gt;</code><br />
<code>#include &lt;stdio.h&gt;</code><br />
<code>#include &lt;string.h&gt;</code><br />
<code>#include &lt;unistd.h&gt;</code><br />
<code>#include &lt;fcntl.h&gt;</code><br />
<code>#include &lt;sys/stat.h&gt;</code><br />
<code>#include &lt;dirent.h&gt;</code><br />
<code>#include &lt;errno.h&gt;</code><br />
<code>#include &lt;sys/time.h&gt;</code><br />
</div>
<p><a href="passthrough_8c_source.html">Go to the source code of this file.</a></p>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>This file system mirrors the existing file system hierarchy of the system, starting at the root file system. This is implemented by just "passing through" all requests to the corresponding user-space libc functions. Its performance is terrible.</p>
<p>Compile with </p><pre class="fragment">gcc -Wall passthrough.c `pkg-config fuse3 --cflags --libs` -o passthrough
</pre><h2>Source code</h2>
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment">  FUSE: Filesystem in Userspace</span></div><div class="line"><span class="comment">  Copyright (C) 2001-2007  Miklos Szeredi &lt;miklos@szeredi.hu&gt;</span></div><div class="line"><span class="comment">  Copyright (C) 2011       Sebastian Pipping &lt;sebastian@pipping.org&gt;</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  This program can be distributed under the terms of the GNU GPL.</span></div><div class="line"><span class="comment">  See the file COPYING.</span></div><div class="line"><span class="comment">*/</span></div><div class="line"></div><div class="line"><span class="preprocessor">#define FUSE_USE_VERSION 31</span></div><div class="line"></div><div class="line"><span class="preprocessor">#ifdef HAVE_CONFIG_H</span></div><div class="line"><span class="preprocessor">#include &lt;config.h&gt;</span></div><div class="line"><span class="preprocessor">#endif</span></div><div class="line"></div><div class="line"><span class="preprocessor">#define _GNU_SOURCE</span></div><div class="line"></div><div class="line"><span class="preprocessor">#ifdef linux</span></div><div class="line"><span class="comment">/* For pread()/pwrite()/utimensat() */</span></div><div class="line"><span class="preprocessor">#define _XOPEN_SOURCE 700</span></div><div class="line"><span class="preprocessor">#endif</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="fuse_8h.html">fuse.h</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;stdio.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;string.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;unistd.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;fcntl.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;sys/stat.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;dirent.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;errno.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;sys/time.h&gt;</span></div><div class="line"><span class="preprocessor">#ifdef HAVE_SETXATTR</span></div><div class="line"><span class="preprocessor">#include &lt;sys/xattr.h&gt;</span></div><div class="line"><span class="preprocessor">#endif</span></div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> *xmp_init(<span class="keyword">struct</span> <a class="code" href="structfuse__conn__info.html">fuse_conn_info</a> *conn,</div><div class="line">                      <span class="keyword">struct</span> <a class="code" href="structfuse__config.html">fuse_config</a> *cfg)</div><div class="line">{</div><div class="line">        (void) conn;</div><div class="line">        cfg-&gt;<a class="code" href="structfuse__config.html#adf78e64e79e31c4fe1464cd0744ea725">use_ino</a> = 1;</div><div class="line"></div><div class="line">        <span class="comment">/* Pick up changes from lower filesystem right away. This is</span></div><div class="line"><span class="comment">           also necessary for better hardlink support. When the kernel</span></div><div class="line"><span class="comment">           calls the unlink() handler, it does not know the inode of</span></div><div class="line"><span class="comment">           the to-be-removed entry and can therefore not invalidate</span></div><div class="line"><span class="comment">           the cache of the associated inode - resulting in an</span></div><div class="line"><span class="comment">           incorrect st_nlink value being reported for any remaining</span></div><div class="line"><span class="comment">           hardlinks to this inode. */</span></div><div class="line">        cfg-&gt;<a class="code" href="structfuse__config.html#a9bc2e3b1d8a4410215cd620553e61b62">entry_timeout</a> = 0;</div><div class="line">        cfg-&gt;<a class="code" href="structfuse__config.html#aeba85551d9498ca85fa2bf13b5e78eda">attr_timeout</a> = 0;</div><div class="line">        cfg-&gt;<a class="code" href="structfuse__config.html#ab4205f7343afe6e20edfbfb64cb90248">negative_timeout</a> = 0;</div><div class="line"></div><div class="line">        <span class="keywordflow">return</span> NULL;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_getattr(<span class="keyword">const</span> <span class="keywordtype">char</span> *path, <span class="keyword">struct</span> stat *stbuf,</div><div class="line">                       <span class="keyword">struct</span> <a class="code" href="structfuse__file__info.html">fuse_file_info</a> *fi)</div><div class="line">{</div><div class="line">        (void) fi;</div><div class="line">        <span class="keywordtype">int</span> res;</div><div class="line"></div><div class="line">        res = lstat(path, stbuf);</div><div class="line">        <span class="keywordflow">if</span> (res == -1)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line"></div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_access(<span class="keyword">const</span> <span class="keywordtype">char</span> *path, <span class="keywordtype">int</span> mask)</div><div class="line">{</div><div class="line">        <span class="keywordtype">int</span> res;</div><div class="line"></div><div class="line">        res = <a class="code" href="structfuse__operations.html#a4dd366b9f74ead6927fb75afb91863bc">access</a>(path, mask);</div><div class="line">        <span class="keywordflow">if</span> (res == -1)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line"></div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_readlink(<span class="keyword">const</span> <span class="keywordtype">char</span> *path, <span class="keywordtype">char</span> *buf, <span class="keywordtype">size_t</span> size)</div><div class="line">{</div><div class="line">        <span class="keywordtype">int</span> res;</div><div class="line"></div><div class="line">        res = <a class="code" href="structfuse__operations.html#a0a7fe4e7fe5db55e96ef6adaf64c09e2">readlink</a>(path, buf, size - 1);</div><div class="line">        <span class="keywordflow">if</span> (res == -1)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line"></div><div class="line">        buf[res] = <span class="charliteral">&#39;\0&#39;</span>;</div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_readdir(<span class="keyword">const</span> <span class="keywordtype">char</span> *path, <span class="keywordtype">void</span> *buf, <a class="code" href="fuse_8h.html#a7dd132de66a5cc2add2a4eff5d435660">fuse_fill_dir_t</a> filler,</div><div class="line">                       off_t offset, <span class="keyword">struct</span> <a class="code" href="structfuse__file__info.html">fuse_file_info</a> *fi,</div><div class="line">                       <span class="keyword">enum</span> <a class="code" href="fuse_8h.html#af2bcf2a473b41b3cc8da8c079656a074">fuse_readdir_flags</a> flags)</div><div class="line">{</div><div class="line">        DIR *dp;</div><div class="line">        <span class="keyword">struct </span>dirent *de;</div><div class="line"></div><div class="line">        (void) offset;</div><div class="line">        (void) fi;</div><div class="line">        (void) flags;</div><div class="line"></div><div class="line">        dp = opendir(path);</div><div class="line">        <span class="keywordflow">if</span> (dp == NULL)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line"></div><div class="line">        <span class="keywordflow">while</span> ((de = readdir(dp)) != NULL) {</div><div class="line">                <span class="keyword">struct </span>stat st;</div><div class="line">                memset(&amp;st, 0, <span class="keyword">sizeof</span>(st));</div><div class="line">                st.st_ino = de-&gt;d_ino;</div><div class="line">                st.st_mode = de-&gt;d_type &lt;&lt; 12;</div><div class="line">                <span class="keywordflow">if</span> (filler(buf, de-&gt;d_name, &amp;st, 0, 0))</div><div class="line">                        <span class="keywordflow">break</span>;</div><div class="line">        }</div><div class="line"></div><div class="line">        closedir(dp);</div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_mknod(<span class="keyword">const</span> <span class="keywordtype">char</span> *path, mode_t mode, dev_t rdev)</div><div class="line">{</div><div class="line">        <span class="keywordtype">int</span> res;</div><div class="line"></div><div class="line">        <span class="comment">/* On Linux this could just be &#39;mknod(path, mode, rdev)&#39; but this</span></div><div class="line"><span class="comment">           is more portable */</span></div><div class="line">        <span class="keywordflow">if</span> (S_ISREG(mode)) {</div><div class="line">                res = open(path, O_CREAT | O_EXCL | O_WRONLY, mode);</div><div class="line">                <span class="keywordflow">if</span> (res &gt;= 0)</div><div class="line">                        res = close(res);</div><div class="line">        } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (S_ISFIFO(mode))</div><div class="line">                res = mkfifo(path, mode);</div><div class="line">        <span class="keywordflow">else</span></div><div class="line">                res = mknod(path, mode, rdev);</div><div class="line">        <span class="keywordflow">if</span> (res == -1)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line"></div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_mkdir(<span class="keyword">const</span> <span class="keywordtype">char</span> *path, mode_t mode)</div><div class="line">{</div><div class="line">        <span class="keywordtype">int</span> res;</div><div class="line"></div><div class="line">        res = mkdir(path, mode);</div><div class="line">        <span class="keywordflow">if</span> (res == -1)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line"></div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_unlink(<span class="keyword">const</span> <span class="keywordtype">char</span> *path)</div><div class="line">{</div><div class="line">        <span class="keywordtype">int</span> res;</div><div class="line"></div><div class="line">        res = unlink(path);</div><div class="line">        <span class="keywordflow">if</span> (res == -1)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line"></div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_rmdir(<span class="keyword">const</span> <span class="keywordtype">char</span> *path)</div><div class="line">{</div><div class="line">        <span class="keywordtype">int</span> res;</div><div class="line"></div><div class="line">        res = rmdir(path);</div><div class="line">        <span class="keywordflow">if</span> (res == -1)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line"></div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_symlink(<span class="keyword">const</span> <span class="keywordtype">char</span> *from, <span class="keyword">const</span> <span class="keywordtype">char</span> *to)</div><div class="line">{</div><div class="line">        <span class="keywordtype">int</span> res;</div><div class="line"></div><div class="line">        res = symlink(from, to);</div><div class="line">        <span class="keywordflow">if</span> (res == -1)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line"></div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_rename(<span class="keyword">const</span> <span class="keywordtype">char</span> *from, <span class="keyword">const</span> <span class="keywordtype">char</span> *to, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> flags)</div><div class="line">{</div><div class="line">        <span class="keywordtype">int</span> res;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (flags)</div><div class="line">                <span class="keywordflow">return</span> -EINVAL;</div><div class="line"></div><div class="line">        res = rename(from, to);</div><div class="line">        <span class="keywordflow">if</span> (res == -1)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line"></div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_link(<span class="keyword">const</span> <span class="keywordtype">char</span> *from, <span class="keyword">const</span> <span class="keywordtype">char</span> *to)</div><div class="line">{</div><div class="line">        <span class="keywordtype">int</span> res;</div><div class="line"></div><div class="line">        res = link(from, to);</div><div class="line">        <span class="keywordflow">if</span> (res == -1)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line"></div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_chmod(<span class="keyword">const</span> <span class="keywordtype">char</span> *path, mode_t mode,</div><div class="line">                     <span class="keyword">struct</span> <a class="code" href="structfuse__file__info.html">fuse_file_info</a> *fi)</div><div class="line">{</div><div class="line">        (void) fi;</div><div class="line">        <span class="keywordtype">int</span> res;</div><div class="line"></div><div class="line">        res = chmod(path, mode);</div><div class="line">        <span class="keywordflow">if</span> (res == -1)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line"></div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_chown(<span class="keyword">const</span> <span class="keywordtype">char</span> *path, uid_t uid, gid_t gid,</div><div class="line">                     <span class="keyword">struct</span> <a class="code" href="structfuse__file__info.html">fuse_file_info</a> *fi)</div><div class="line">{</div><div class="line">        (void) fi;</div><div class="line">        <span class="keywordtype">int</span> res;</div><div class="line"></div><div class="line">        res = lchown(path, uid, gid);</div><div class="line">        <span class="keywordflow">if</span> (res == -1)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line"></div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_truncate(<span class="keyword">const</span> <span class="keywordtype">char</span> *path, off_t size,</div><div class="line">                        <span class="keyword">struct</span> <a class="code" href="structfuse__file__info.html">fuse_file_info</a> *fi)</div><div class="line">{</div><div class="line">        <span class="keywordtype">int</span> res;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (fi != NULL)</div><div class="line">                res = ftruncate(fi-&gt;<a class="code" href="structfuse__file__info.html#a45314d0b92a8d4c9de33d996aa59ada8">fh</a>, size);</div><div class="line">        <span class="keywordflow">else</span></div><div class="line">                res = truncate(path, size);</div><div class="line">        <span class="keywordflow">if</span> (res == -1)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line"></div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="preprocessor">#ifdef HAVE_UTIMENSAT</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_utimens(<span class="keyword">const</span> <span class="keywordtype">char</span> *path, <span class="keyword">const</span> <span class="keyword">struct</span> timespec ts[2],</div><div class="line">                       <span class="keyword">struct</span> <a class="code" href="structfuse__file__info.html">fuse_file_info</a> *fi)</div><div class="line">{</div><div class="line">        (void) fi;</div><div class="line">        <span class="keywordtype">int</span> res;</div><div class="line"></div><div class="line">        <span class="comment">/* don&#39;t use utime/utimes since they follow symlinks */</span></div><div class="line">        res = utimensat(0, path, ts, AT_SYMLINK_NOFOLLOW);</div><div class="line">        <span class="keywordflow">if</span> (res == -1)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line"></div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"><span class="preprocessor">#endif</span></div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_create(<span class="keyword">const</span> <span class="keywordtype">char</span> *path, mode_t mode,</div><div class="line">                      <span class="keyword">struct</span> <a class="code" href="structfuse__file__info.html">fuse_file_info</a> *fi)</div><div class="line">{</div><div class="line">        <span class="keywordtype">int</span> res;</div><div class="line"></div><div class="line">        res = open(path, fi-&gt;<a class="code" href="structfuse__file__info.html#ae7d31802727be19670193a411647bca5">flags</a>, mode);</div><div class="line">        <span class="keywordflow">if</span> (res == -1)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line"></div><div class="line">        fi-&gt;<a class="code" href="structfuse__file__info.html#a45314d0b92a8d4c9de33d996aa59ada8">fh</a> = res;</div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_open(<span class="keyword">const</span> <span class="keywordtype">char</span> *path, <span class="keyword">struct</span> <a class="code" href="structfuse__file__info.html">fuse_file_info</a> *fi)</div><div class="line">{</div><div class="line">        <span class="keywordtype">int</span> res;</div><div class="line"></div><div class="line">        res = open(path, fi-&gt;<a class="code" href="structfuse__file__info.html#ae7d31802727be19670193a411647bca5">flags</a>);</div><div class="line">        <span class="keywordflow">if</span> (res == -1)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line"></div><div class="line">        fi-&gt;<a class="code" href="structfuse__file__info.html#a45314d0b92a8d4c9de33d996aa59ada8">fh</a> = res;</div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_read(<span class="keyword">const</span> <span class="keywordtype">char</span> *path, <span class="keywordtype">char</span> *buf, <span class="keywordtype">size_t</span> size, off_t offset,</div><div class="line">                    <span class="keyword">struct</span> <a class="code" href="structfuse__file__info.html">fuse_file_info</a> *fi)</div><div class="line">{</div><div class="line">        <span class="keywordtype">int</span> fd;</div><div class="line">        <span class="keywordtype">int</span> res;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span>(fi == NULL)</div><div class="line">                fd = open(path, O_RDONLY);</div><div class="line">        <span class="keywordflow">else</span></div><div class="line">                fd = fi-&gt;<a class="code" href="structfuse__file__info.html#a45314d0b92a8d4c9de33d996aa59ada8">fh</a>;</div><div class="line">        </div><div class="line">        <span class="keywordflow">if</span> (fd == -1)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line"></div><div class="line">        res = pread(fd, buf, size, offset);</div><div class="line">        <span class="keywordflow">if</span> (res == -1)</div><div class="line">                res = -errno;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span>(fi == NULL)</div><div class="line">                close(fd);</div><div class="line">        <span class="keywordflow">return</span> res;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_write(<span class="keyword">const</span> <span class="keywordtype">char</span> *path, <span class="keyword">const</span> <span class="keywordtype">char</span> *buf, <span class="keywordtype">size_t</span> size,</div><div class="line">                     off_t offset, <span class="keyword">struct</span> <a class="code" href="structfuse__file__info.html">fuse_file_info</a> *fi)</div><div class="line">{</div><div class="line">        <span class="keywordtype">int</span> fd;</div><div class="line">        <span class="keywordtype">int</span> res;</div><div class="line"></div><div class="line">        (void) fi;</div><div class="line">        <span class="keywordflow">if</span>(fi == NULL)</div><div class="line">                fd = open(path, O_WRONLY);</div><div class="line">        <span class="keywordflow">else</span></div><div class="line">                fd = fi-&gt;<a class="code" href="structfuse__file__info.html#a45314d0b92a8d4c9de33d996aa59ada8">fh</a>;</div><div class="line">        </div><div class="line">        <span class="keywordflow">if</span> (fd == -1)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line"></div><div class="line">        res = pwrite(fd, buf, size, offset);</div><div class="line">        <span class="keywordflow">if</span> (res == -1)</div><div class="line">                res = -errno;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span>(fi == NULL)</div><div class="line">                close(fd);</div><div class="line">        <span class="keywordflow">return</span> res;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_statfs(<span class="keyword">const</span> <span class="keywordtype">char</span> *path, <span class="keyword">struct</span> statvfs *stbuf)</div><div class="line">{</div><div class="line">        <span class="keywordtype">int</span> res;</div><div class="line"></div><div class="line">        res = statvfs(path, stbuf);</div><div class="line">        <span class="keywordflow">if</span> (res == -1)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line"></div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_release(<span class="keyword">const</span> <span class="keywordtype">char</span> *path, <span class="keyword">struct</span> <a class="code" href="structfuse__file__info.html">fuse_file_info</a> *fi)</div><div class="line">{</div><div class="line">        (void) path;</div><div class="line">        close(fi-&gt;<a class="code" href="structfuse__file__info.html#a45314d0b92a8d4c9de33d996aa59ada8">fh</a>);</div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_fsync(<span class="keyword">const</span> <span class="keywordtype">char</span> *path, <span class="keywordtype">int</span> isdatasync,</div><div class="line">                     <span class="keyword">struct</span> <a class="code" href="structfuse__file__info.html">fuse_file_info</a> *fi)</div><div class="line">{</div><div class="line">        <span class="comment">/* Just a stub.  This method is optional and can safely be left</span></div><div class="line"><span class="comment">           unimplemented */</span></div><div class="line"></div><div class="line">        (void) path;</div><div class="line">        (void) isdatasync;</div><div class="line">        (void) fi;</div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="preprocessor">#ifdef HAVE_POSIX_FALLOCATE</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_fallocate(<span class="keyword">const</span> <span class="keywordtype">char</span> *path, <span class="keywordtype">int</span> mode,</div><div class="line">                        off_t offset, off_t length, <span class="keyword">struct</span> <a class="code" href="structfuse__file__info.html">fuse_file_info</a> *fi)</div><div class="line">{</div><div class="line">        <span class="keywordtype">int</span> fd;</div><div class="line">        <span class="keywordtype">int</span> res;</div><div class="line"></div><div class="line">        (void) fi;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (mode)</div><div class="line">                <span class="keywordflow">return</span> -EOPNOTSUPP;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span>(fi == NULL)</div><div class="line">                fd = open(path, O_WRONLY);</div><div class="line">        <span class="keywordflow">else</span></div><div class="line">                fd = fi-&gt;<a class="code" href="structfuse__file__info.html#a45314d0b92a8d4c9de33d996aa59ada8">fh</a>;</div><div class="line">        </div><div class="line">        <span class="keywordflow">if</span> (fd == -1)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line"></div><div class="line">        res = -posix_fallocate(fd, offset, length);</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span>(fi == NULL)</div><div class="line">                close(fd);</div><div class="line">        <span class="keywordflow">return</span> res;</div><div class="line">}</div><div class="line"><span class="preprocessor">#endif</span></div><div class="line"></div><div class="line"><span class="preprocessor">#ifdef HAVE_SETXATTR</span></div><div class="line"><span class="comment">/* xattr operations are optional and can safely be left unimplemented */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_setxattr(<span class="keyword">const</span> <span class="keywordtype">char</span> *path, <span class="keyword">const</span> <span class="keywordtype">char</span> *name, <span class="keyword">const</span> <span class="keywordtype">char</span> *value,</div><div class="line">                        <span class="keywordtype">size_t</span> size, <span class="keywordtype">int</span> flags)</div><div class="line">{</div><div class="line">        <span class="keywordtype">int</span> res = lsetxattr(path, name, value, size, flags);</div><div class="line">        <span class="keywordflow">if</span> (res == -1)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_getxattr(<span class="keyword">const</span> <span class="keywordtype">char</span> *path, <span class="keyword">const</span> <span class="keywordtype">char</span> *name, <span class="keywordtype">char</span> *value,</div><div class="line">                        <span class="keywordtype">size_t</span> size)</div><div class="line">{</div><div class="line">        <span class="keywordtype">int</span> res = lgetxattr(path, name, value, size);</div><div class="line">        <span class="keywordflow">if</span> (res == -1)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line">        <span class="keywordflow">return</span> res;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_listxattr(<span class="keyword">const</span> <span class="keywordtype">char</span> *path, <span class="keywordtype">char</span> *list, <span class="keywordtype">size_t</span> size)</div><div class="line">{</div><div class="line">        <span class="keywordtype">int</span> res = llistxattr(path, list, size);</div><div class="line">        <span class="keywordflow">if</span> (res == -1)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line">        <span class="keywordflow">return</span> res;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> xmp_removexattr(<span class="keyword">const</span> <span class="keywordtype">char</span> *path, <span class="keyword">const</span> <span class="keywordtype">char</span> *name)</div><div class="line">{</div><div class="line">        <span class="keywordtype">int</span> res = lremovexattr(path, name);</div><div class="line">        <span class="keywordflow">if</span> (res == -1)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"><span class="preprocessor">#endif </span><span class="comment">/* HAVE_SETXATTR */</span><span class="preprocessor"></span></div><div class="line"></div><div class="line"><span class="preprocessor">#ifdef HAVE_COPY_FILE_RANGE</span></div><div class="line"><span class="keyword">static</span> ssize_t xmp_copy_file_range(<span class="keyword">const</span> <span class="keywordtype">char</span> *path_in,</div><div class="line">                                   <span class="keyword">struct</span> <a class="code" href="structfuse__file__info.html">fuse_file_info</a> *fi_in,</div><div class="line">                                   off_t offset_in, <span class="keyword">const</span> <span class="keywordtype">char</span> *path_out,</div><div class="line">                                   <span class="keyword">struct</span> <a class="code" href="structfuse__file__info.html">fuse_file_info</a> *fi_out,</div><div class="line">                                   off_t offset_out, <span class="keywordtype">size_t</span> len, <span class="keywordtype">int</span> flags)</div><div class="line">{</div><div class="line">        <span class="keywordtype">int</span> fd_in, fd_out;</div><div class="line">        ssize_t res;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span>(fi_in == NULL)</div><div class="line">                fd_in = open(path_in, O_RDONLY);</div><div class="line">        <span class="keywordflow">else</span></div><div class="line">                fd_in = fi_in-&gt;<a class="code" href="structfuse__file__info.html#a45314d0b92a8d4c9de33d996aa59ada8">fh</a>;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (fd_in == -1)</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span>(fi_out == NULL)</div><div class="line">                fd_out = open(path_out, O_WRONLY);</div><div class="line">        <span class="keywordflow">else</span></div><div class="line">                fd_out = fi_out-&gt;<a class="code" href="structfuse__file__info.html#a45314d0b92a8d4c9de33d996aa59ada8">fh</a>;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (fd_out == -1) {</div><div class="line">                close(fd_in);</div><div class="line">                <span class="keywordflow">return</span> -errno;</div><div class="line">        }</div><div class="line"></div><div class="line">        res = copy_file_range(fd_in, &amp;offset_in, fd_out, &amp;offset_out, len,</div><div class="line">                              flags);</div><div class="line">        <span class="keywordflow">if</span> (res == -1)</div><div class="line">                res = -errno;</div><div class="line"></div><div class="line">        close(fd_in);</div><div class="line">        close(fd_out);</div><div class="line"></div><div class="line">        <span class="keywordflow">return</span> res;</div><div class="line">}</div><div class="line"><span class="preprocessor">#endif</span></div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keyword">struct </span><a class="code" href="structfuse__operations.html">fuse_operations</a> xmp_oper = {</div><div class="line">        .<a class="code" href="structfuse__operations.html#a0ad1f7c4105ee062528c767da88060f0">init</a>           = xmp_init,</div><div class="line">        .getattr        = xmp_getattr,</div><div class="line">        .access         = xmp_access,</div><div class="line">        .readlink       = xmp_readlink,</div><div class="line">        .readdir        = xmp_readdir,</div><div class="line">        .mknod          = xmp_mknod,</div><div class="line">        .mkdir          = xmp_mkdir,</div><div class="line">        .symlink        = xmp_symlink,</div><div class="line">        .unlink         = xmp_unlink,</div><div class="line">        .rmdir          = xmp_rmdir,</div><div class="line">        .rename         = xmp_rename,</div><div class="line">        .link           = xmp_link,</div><div class="line">        .chmod          = xmp_chmod,</div><div class="line">        .chown          = xmp_chown,</div><div class="line">        .truncate       = xmp_truncate,</div><div class="line"><span class="preprocessor">#ifdef HAVE_UTIMENSAT</span></div><div class="line">        .utimens        = xmp_utimens,</div><div class="line"><span class="preprocessor">#endif</span></div><div class="line">        .open           = xmp_open,</div><div class="line">        .create         = xmp_create,</div><div class="line">        .read           = xmp_read,</div><div class="line">        .write          = xmp_write,</div><div class="line">        .statfs         = xmp_statfs,</div><div class="line">        .release        = xmp_release,</div><div class="line">        .fsync          = xmp_fsync,</div><div class="line"><span class="preprocessor">#ifdef HAVE_POSIX_FALLOCATE</span></div><div class="line">        .fallocate      = xmp_fallocate,</div><div class="line"><span class="preprocessor">#endif</span></div><div class="line"><span class="preprocessor">#ifdef HAVE_SETXATTR</span></div><div class="line">        .setxattr       = xmp_setxattr,</div><div class="line">        .getxattr       = xmp_getxattr,</div><div class="line">        .listxattr      = xmp_listxattr,</div><div class="line">        .removexattr    = xmp_removexattr,</div><div class="line"><span class="preprocessor">#endif</span></div><div class="line"><span class="preprocessor">#ifdef HAVE_COPY_FILE_RANGE</span></div><div class="line">        .copy_file_range = xmp_copy_file_range,</div><div class="line"><span class="preprocessor">#endif</span></div><div class="line">};</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])</div><div class="line">{</div><div class="line">        umask(0);</div><div class="line">        <span class="keywordflow">return</span> <a class="code" href="fuse_8h.html#ac99b844cee7aaa8fb4e35df5b5488d82">fuse_main</a>(argc, argv, &amp;xmp_oper, NULL);</div><div class="line">}</div></div><!-- fragment --> 
<p class="definition">Definition in file <a class="el" href="passthrough_8c_source.html">passthrough.c</a>.</p>
</div></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>
